//package com.example.prison.controller;
//
//import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
//import com.example.prison.config.Response;
//import com.example.prison.entity.PersonnelManagement;
//import com.example.prison.service.PersonnelManagementService;
//import com.example.prison.util.HttpUtils;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.http.HttpResponse;
//import org.apache.http.util.EntityUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@Slf4j
//@Api("短信发送")
//@RestController
//@RequestMapping("/api")
//public class SendMessageController {
//
//    @Autowired
//    private PersonnelManagementService personnelManagementService;
//
//    @ApiOperation("短信发送")
//    @GetMapping("/sendMessage")
//    public Response<?> sendMessage(@RequestParam(value = "pushPersonnel") String pushPersonnel) {
//        log.info("短信发送");
//        if(ObjectUtils.isEmpty(personnelManagementService.getOneByName(pushPersonnel))) {
//            return Response.error("该推送人员不存在");
//        }
//        PersonnelManagement personnel = personnelManagementService.getOneByName(pushPersonnel);
//        if(ObjectUtils.isEmpty(personnel.getPhone())) {
//            return Response.error("该推送人员无联系方式");
//        }
//
//        //短信api调用地址
//        String host = "https://dfsns.market.alicloudapi.com";
//        //请求路径
//        String path = "/data/send_sms";
//        //请求方式
//        String method = "POST";
//        //appcode：自己的AppCode，可以在自己的控制台找到，是一串32位的字符串
//        String appcode = "14xfa0523x3s2fe8ep0u54te14c2w36ad";
//        Map<String, String> headers = new HashMap<String, String>();
//        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
//        headers.put("Authorization", "APPCODE " + appcode);
//        //根据API的要求，定义相对应的Content-Type
//        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//        Map<String, String> querys = new HashMap<String, String>();
//        Map<String, String> bodys = new HashMap<String, String>();
//
////        //使用随机数生成4位验证码
//        StringBuilder stringBuilder = new StringBuilder();
////        for (int i = 0; i < 4; i++) {
////            int randomNum = (int) (Math.random()*10);
////            stringBuilder.append(randomNum);
////        }
//        String str = "您收到一条报警推送，请尽快处理";
//        stringBuilder.append(str);
//        String code = stringBuilder.toString();
//        //这里是要发送给用户的验证码，我们使用了随机数进行生成
//        bodys.put("content", "code:"+code);
//        //这里是接受短信的手机号码，我们在实际开发时这里就不能写死了
//        String phone = personnel.getPhone();
//        bodys.put("phone_number", phone);
//        //这里是发送短信的模板ID：代表整体短信文案模板
//        bodys.put("template_id", "TPL_0000");
//        try {
//            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
//            System.out.println(response.toString());
//            //获取response的body
//            System.out.println(EntityUtils.toString(response.getEntity()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return Response.success("获取成功！");
//    }
//
//}
